//
//  ActionViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/27.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxCocoa
import RxSwift
import Action

class ActionViewController: BaseViewController {
    
    var button = UIButton(type: .system)
    let disposed = DisposeBag()

    override func viewDidLoad() {
        super.viewDidLoad()
 
        button.setTitle("点我", for: .normal)
        button.frame = CGRect(x: 10, y: 80, width: 100, height: 33)
        button.backgroundColor = UIColor.lightGray.withAlphaComponent(0.2)
        
        self.view.addSubview(button)
        
        
        
//        let action = Action<Void, Void> {
//            print("button action")
//            return .empty()
//        }
//        button.rx.action = action
        
        
        
        let action = Action<String, String>(enabledIf: Observable.just(true), workFactory: { input in
            print(input)
            return .just("world")
        })
        
        button.rx.bind(to: action) { (button) -> (String) in
            print("bind")
            return "hello"
        }
        
        action.elements
            .subscribe { (eve) in
                print(eve)
            }
            .disposed(by: disposed)
        
    }
}
